package cn.hchaojie.blog.service;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import cn.hchaojie.blog.domain.Category;
import cn.hchaojie.blog.mapper.CategoryMapper;
import cn.hchaojie.blog.utils.SessionFactoryUtils;

/**
 * service职责：开始事务，提交事务，调用mapper做数据库查询
 * 处理业务逻辑，
 * @author hchaojie
 *
 */
public class CategoryService {
	CategoryMapper mapper;
	
	/**
	 * 增强foo方法，方法执行之前插入一些代码
	 * 
	 * 方法执行之后，加入另外的一些代码
	 */
	public void foo() {
		System.out.println("foo");
	}

	public List<Category> findAll() {
//		SqlSessionFactory factory = SessionFactoryUtils.getFactory();
//		SqlSession session = factory.openSession();
//		mapper = session.getMapper(CategoryMapper.class);

		List<Category> data = mapper.findAll();
		
//		session.close();
		
		return data;
	}
	
	public void insert(Category category) {
		mapper.insert(category);
	}
	
	public void update(Category category) {
		mapper.update(category);
	}
	
	public void delete(int id) throws SQLException {
		mapper.delete(id);
	}
}
